//
//  Auction_Main_CellHeader_WX.m
//  ZITHER
//
//  Created by weixin on 2019/5/28.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Auction_Main_CellHeader_WX.h"
#import "Auction_SpecialSaleDetails_VC_WX.h"

@implementation Auction_Main_CellHeader_WX

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        self.userInteractionEnabled = YES;
        [self addGestureRecognizer:tap];
        
        [[tap rac_gestureSignal]subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
//            Auction_SpecialSaleDetails_VC_WX *vc = [[Auction_SpecialSaleDetails_VC_WX alloc]init];
//            [self.getNav pushViewController:vc animated:YES];
        }];
       
        BaseView *view = [[BaseView alloc]initWithFrame:frame];
        view.backgroundColor = HexColor(0xeeeeee);
        [self addSubview:view];
        
        [self setUI];
        
        self.countRecommend = 3;
        [self  UPconuntRecommend];
    }
    return self;
}

-(void)setModel:(specialSaleSceneid *)model{
    _model = model;
    self.countRecommend = model.recommendCount;
    [self UPconuntRecommend];
    
    
}

-(void)setUI{

//    [self addSubview:self.titleV];
//    [self addSubview:self.titleLab];
    [self addSubview:self.titleSubBtn];

//    [self addSubview:self.countDownView];
    
//    [self.titleV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self).offset(15);
//        make.right.equalTo(self).offset(-15);
//        make.height.mas_equalTo(90);
//        make.top.equalTo(self).offset(15);
//    }];
    
//    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self).offset(15);
//        make.height.mas_equalTo(21);
//        make.top.equalTo(self).offset(30);
//    }];
    
    [self.titleSubBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.height.mas_equalTo(18);
        make.top.equalTo(self).offset(12);
    }];
    
    
    
//    [self.countDownView mas_makeConstraints:^(MASConstraintMaker *make) {
//
//    }];
    
    
}

//-(Auction_MainCellHeaderTitle_View_WX *)titleV{
//    if (!_titleV) {
//        _titleV = [[Auction_MainCellHeaderTitle_View_WX alloc]init];
//    }
//    return _titleV;
//}

//- (BaseLab *)titleLab{
//    if (!_titleLab) {
//        _titleLab = [BaseLab initCustomLab:@"特卖专场" color:HexColor(0x333333) font:[UIFont fontWithName:@"PingFangSC-Semibold" size:20]];
//        _titleLab.backgroundColor = [UIColor clearColor];
//
//    }
//    return _titleLab;
//}

-(BaseBtn *)titleSubBtn{
    
    if (!_titleSubBtn) {
        _titleSubBtn = [BaseBtn initCustomBtnImageAndTitles:@[@" 查看全部",@" 查看已报价"] images:@[@"交易_查看全部",@"交易_查看已报价"] color:@[HexColor(0x333333)]];
        _titleSubBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
        _titleSubBtn.backgroundColor = [UIColor clearColor];
        
        [[_titleSubBtn addTag]subscribeNext:^(id  _Nullable x) {
            _titleSubBtn.selected = !_titleSubBtn.selected;
     
            
        }];
    }
    return _titleSubBtn;
}

-(NSMutableArray<Auction_MainCellHeaderRecommend_View_WX *> *)arrM{
    if (!_arrM) {
        _arrM = [[NSMutableArray alloc]init];
        for (int i = 0; i <3; i++) {
            Auction_MainCellHeaderRecommend_View_WX *view = [[Auction_MainCellHeaderRecommend_View_WX alloc]initWithFrame:CGRectZero];
            view.tag = 255+i;
            [self addSubview:view];
            [[view addTag]subscribeNext:^(id  _Nullable x) {
              specialSaleSceneidList * model = self.model.list[view.tag-255];
                Auction_SpecialSaleDetails_VC_WX *vc = [[Auction_SpecialSaleDetails_VC_WX alloc]init];
                vc.type = [model.type isEqualToString:@"QUOTE"]?1:0;
                vc.DetailsId = model.id;
                
                [[self getNav]pushViewController:vc animated:YES];
            }];
            if (i == 0) {
                [view mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(15);
                    make.top.equalTo(self.titleSubBtn.mas_bottom).offset(10);
                    make.height.mas_equalTo((kScreenW-30)/344.0*277);
                    make.width.mas_equalTo(kScreenW-30);
                }];
            }else{
                [view mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(15);
                    make.top.equalTo(_arrM[i-1].mas_bottom).offset(10);
                    make.height.mas_equalTo((kScreenW-30)/344.0*277);
                    make.width.mas_equalTo(kScreenW-30);
                }];
            }
                [_arrM addObject:view];
        }
    }
    return _arrM;
}

-(void)UPconuntRecommend{
    
    for (int i = 0; i<3; i++) {
       Auction_MainCellHeaderRecommend_View_WX * RecommendV = self.arrM [i];
        if (i<self.countRecommend) {
            RecommendV.hidden = NO;
            RecommendV.model = self.model.list[i];
        }else{
            RecommendV.hidden = YES;
        }
    }
    
    
    
}

/**
 titleV
 titleLab
 titleSubBtn
 countDownView
 */




@end
